/**
 * npm i axios
 * npm i qs
 */
import axios from "axios";
// import qs from "qs";

// 创建实例
const service = axios.create({
	baseURL:
    process.env.NODE_ENV === "production"? "https://api.shixianjia.com/api": "/api",
	timeout: 10000,
});
service.interceptors.request.use((config) => {
	localStorage.setItem(
		"token",
		"Bearer 35C12FDDAB326D5B71D3609879D75BA8771585818E72A5E1CCCAF936EA827B8E"
	);
	const token = localStorage.getItem("token");
	// 配置请求头
	config.headers = {
		"Content-Type": "application/json",
		"Cache-Control": "no-cache",
		Pragma: "no-cache",
		Authorization: token,
	};
	return config;
});

// 响应拦截器，数据返回前处理
service.interceptors.response.use(
	(response) => {
		// 请求成功响应，进行逻辑处理
		
		return response.data;
	},
	(error) => {
		return Promise.reject(error?.response);
	}
);

const post = (url) => {
	return function (data,opions) {
		return service
			.post(url, data,opions)
			.then((res) => {
				return res;
			})
			.catch((err) => {
				return err;
			});
	};
};
const get = (url) => {
	return function (params) {
		return service
			.get(url, params)
			.then((res) => {
				return res;
			})
			.catch((err) => {
				return err;
			});
	};
};

export { post, get };
